# -*- encoding=utf8 -*-
__author__ = "xiaoyun461"

from airtest.core.api import *
import logging
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
import uuid
import traceback
from retrying import retry
import time

def height_width():
    global width
    global height
    if G.DEVICE.display_info['orientation'] in [1,3]:        
        height = G.DEVICE.display_info['width']        
        width = G.DEVICE.display_info['height']
    else:
        height = G.DEVICE.display_info['height']
        width = G.DEVICE.display_info['width']
    global half_num
    half_num = (0.5*width,0.5*height)  
    return [height,width] 
def h_w_num(num_01,num_02):
    return (num_01*width,num_02*height)
def sleep_exists(v,max_time):
    for num in range(max_time):
        sleep(1)
        touch(v=half_num,times=5,duration=0.1)
        if exists(v):
            touch(v,times=2,duration=0.5)
            break 
def true_touch(v):
    if exists(v):
        touch(v)
        
def true_touch_sleep(v,num):
    if exists(v):
        touch(v)
        sleep(num)
def es():

    # connect an android phone with adb
    # or use connect_device api

    stop_app("jp.co.cygames.princessconnectredive")
    stop_app("com.estrongs.android.pop")
    start_app("com.estrongs.android.pop") 
    sleep(3)
    #初始化 长宽
    height_width()
    
    touch(v=h_w_num(0.097,0.147))

#     测试失败重试
#     a = 1
#     b = 0
#     c = a/b
    
    sleep(1)
    
    touch(v=h_w_num(0.082,0.116))
    poco(text="data").click()

    result_emple= exists(Template(r"tpl1598346409681.png", record_pos=(0.011, 0.076), resolution=(540, 960)))
    if result_emple:
        home();
        print("请打开root")
    else:
        poco(text="data").click()
        swipe(Template(r"tpl1598275522936.png", record_pos=(0.013, 0.924), resolution=(540, 960)), vector=[-0.1000, -1])

        swipe(Template(r"tpl1598275570612.png", record_pos=(0.143, 0.972), resolution=(540, 960)), vector=[-0.4000, -1])

        swipe(Template(r"tpl1598275606886.png", record_pos=(0.113, 0.92), resolution=(540, 960)), vector=[-0.4000, -1])

        swipe(Template(r"tpl1598275606886.png", record_pos=(0.113, 0.92), resolution=(540, 960)), vector=[-0.4000, -1])

        poco(text="jp.co.cygames.princessconnectredive").click()

        sleep(1)
        touch(Template(r"tpl1598275989144.png", record_pos=(0.017, 0.396), resolution=(540, 960)),duration=0.8)

        poco(text="复制").click()
        poco(text="shared_prefs").click()
        poco(text="粘贴").click()
        poco("com.estrongs.android.pop:id/button_common_dialog_33").click()
        sleep(1)
        stop_app("com.estrongs.android.pop")
def start_pcr(v_num):
    if v_num ==1:
        start_app("jp.co.cygames.princessconnectredive")
    else:
        stop_app("com.njh.biubiu")
        sleep(2)
        start_app("com.njh.biubiu")
        touch(Template(r"tpl1598853022115.png", threshold=0.8, rgb=True, target_pos=6, record_pos=(0.206, -0.406), resolution=(540, 960)))

        sleep(3)

def init_first():
    touch(v=(400,260))
    sleep(20)
    
    #初始化 长宽
    height_width()
    global half_num
    half_num = (0.5*width,0.5*height)
    
    while True:
        sleep(0.5)
        touch(v=half_num,times=20,duration=0.1)
        result_true_touch = exists(Template(r"tpl1598280845433.png", record_pos=(0.132, 0.211), resolution=(960.0, 540.0)))
        if result_true_touch:
            touch(wait(Template(r"tpl1598280845433.png", record_pos=(0.132, 0.211), resolution=(960.0, 540.0))))
            break;
        
    

    sleep(10)
    true_touch_sleep(Template(r"tpl1598347083101.png", record_pos=(0.116, 0.219), resolution=(960, 540)),25)
    for num in range(60):
        result_start_skip = exists(Template(r"tpl1598276814695.png", record_pos=(0.117, 0.103), resolution=(960, 540)))
        if result_start_skip:
            sleep(1)
            touch(Template(r"tpl1598276814695.png", record_pos=(0.117, 0.103), resolution=(960, 540)))
            break
        touch(v=h_w_num(0.533,0.429),times=10,duration=0.1)

    touch(Template(r"tpl1598280924486.png", threshold=0.8, rgb=True, record_pos=(0.432, -0.241), resolution=(960.0, 540.0)))
    sleep(6)
    result_no_next = exists(Template(r"tpl1598546884768.png", record_pos=(-0.007, -0.045), resolution=(960, 540)))

    if result_no_next:
        for num in range(60):
            touch(v=h_w_num(0.937,0.051),times=3,duration=0.1)
            result_ok_start = exists(Template(r"tpl1598280950918.png", record_pos=(0.11, 0.1), resolution=(960.0, 540.0)))
            if result_ok_start:
                sleep(2)
                touch(Template(r"tpl1598280950918.png", record_pos=(0.11, 0.1), resolution=(960.0, 540.0)))
                break
    else:
        touch(Template(r"tpl1598280950918.png", record_pos=(0.11, 0.1), resolution=(960.0, 540.0)))
    

    sleep(1)
    touch(Template(r"tpl1598280971976.png", record_pos=(0.082, -0.028), resolution=(960.0, 540.0)),times=30,duration=0.02)
    touch(Template(r"tpl1598280982634.png", record_pos=(0.118, 0.1), resolution=(960.0, 540.0)))

    sleep(2)
    touch(Template(r"tpl1598281053999.png", record_pos=(0.457, -0.243), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281073535.png", record_pos=(0.334, -0.243), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281080454.png", record_pos=(0.106, 0.104), resolution=(960.0, 540.0)))

    sleep(1)
    true_touch_sleep(Template(r"tpl1598347364372.png", record_pos=(0.116, 0.105), resolution=(960, 540)),10)  
def second_pcr():
    touch(v=half_num)
    for num in range(60):
        touch(v=half_num,times=10,duration=0.1)
        result_es = exists(Template(r"tpl1598358760335.png", record_pos=(-0.002, -0.001), resolution=(960, 540)))
        if result_es:
            touch(v = (0.589*width,0.68*height))
            break    

    for num in range(200):
        touch(v=h_w_num(0.516,0.379),times=40,duration=0.05)
        result_name = exists(Template(r"tpl1598281146393.png", record_pos=(0.002, 0.105), resolution=(960.0, 540.0)))
        if result_name:
            touch(Template(r"tpl1598281146393.png", record_pos=(0.002, 0.105), resolution=(960.0, 540.0)),times=5,duration=0.1)
            break

    sleep(2)
    touch(Template(r"tpl1598281157480.png", record_pos=(0.116, 0.1), resolution=(960.0, 540.0)))
    sleep(1)

    touch(Template(r"tpl1598281157480.png", record_pos=(0.116, 0.1), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281169981.png", record_pos=(0.455, -0.224), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281192664.png", record_pos=(0.34, -0.233), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281199698.png", record_pos=(0.106, 0.105), resolution=(960.0, 540.0)))



    sleep(6)

    touch(Template(r"tpl1598359312767.png", record_pos=(0.433, -0.257), resolution=(960, 540)),duration=0.05,times=5)
    ok_sleep = 1
    while  ok_sleep == 1:
        result_ok_sleep = exists(Template(r"tpl1598281220363.png", record_pos=(0.12, 0.105), resolution=(960.0, 540.0)))
        if result_ok_sleep:
            touch(Template(r"tpl1598281220363.png", record_pos=(0.12, 0.105), resolution=(960.0, 540.0)))
            break        
        touch(v=(0.933*width,0.047*height),times=10,duration=0.1)

    sleep(1)


    touch(Template(r"tpl1598281236970.png", record_pos=(0.458, -0.235), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598281241959.png", record_pos=(0.352, -0.228), resolution=(960.0, 540.0)))
    touch(Template(r"tpl1598281248927.png", record_pos=(0.116, 0.109), resolution=(960.0, 540.0)))
    sleep(4)

    touch(v=half_num,times=5,duration=0.1)
    true_touch_sleep(Template(r"tpl1598359746819.png", record_pos=(0.116, 0.104), resolution=(960, 540)),10)

    touch(v=half_num,times=5,duration=0.1)


    true_touch(Template(r"tpl1598449088877.png", record_pos=(0.106, 0.106), resolution=(960, 540)))
    
def fight_end():
    sleep(2)
    for num in range(60):
        result_ok_fight = exists(Template(r"tpl1598602383436.png", record_pos=(0.001, 0.105), resolution=(960, 540)))

        if result_ok_fight:
            touch(Template(r"tpl1598602383436.png", record_pos=(0.001, 0.105), resolution=(960, 540)))
            touch(v=h_w_num(0.497,0.677),times=10,duration=0.05)
            break
        touch(v=h_w_num(0.465, 0.088),times=3,duration=0.01)
        sleep(3)
    sleep(3)
    for num in range(60):
        result_next_fight_01 = exists(Template(r"tpl1598286786595.png", rgb=True, record_pos=(0.353, 0.234), resolution=(960.0, 540.0)))
        if result_next_fight_01:
            sleep(3)
            touch(Template(r"tpl1598286786595.png", rgb=True, record_pos=(0.353, 0.234), resolution=(960.0, 540.0)))
            break
        touch(v=h_w_num(0.465, 0.088),times=3,duration=0.01)
        sleep(2)    
    sleep(3)
    for num in range(60):
        result_next_fight_02 = exists(Template(r"tpl1598286786595.png", rgb=True, record_pos=(0.353, 0.234), resolution=(960.0, 540.0)))
        if result_next_fight_02:
            sleep(3)
            touch(Template(r"tpl1598286786595.png", rgb=True, record_pos=(0.353, 0.234), resolution=(960.0, 540.0)))
            break
        touch(v=h_w_num(0.465, 0.088),times=3,duration=0.01)
        sleep(2)
    sleep(2)
def third_pcr():
    while True:
        result_pass = exists(Template(r"tpl1598285653871.png", record_pos=(0.086, -0.086), resolution=(960.0, 540.0)))
        if result_pass:
            touch(wait(Template(r"tpl1598285653871.png", record_pos=(0.086, -0.086), resolution=(960.0, 540.0))))
            sleep(1)
            break
        touch(h_w_num(0.491,0.897),times=10,duration=0.1)
        sleep(0.5)
    
    touch(h_w_num(0.500,0.500),times=50,duration=0.1)   
    touch(wait(Template(r"tpl1598285670923.png", threshold=0.8, rgb=True, record_pos=(-0.383, -0.002), resolution=(960.0, 540.0))))

    touch(Template(r"tpl1598285679601.png", record_pos=(0.38, 0.197), resolution=(960.0, 540.0)))




    touch(v=half_num,times=25,duration=0.1)

    touch(Template(r"tpl1598285694583.png", record_pos=(-0.383, -0.101), resolution=(960.0, 540.0)),times=3,duration=0.1)
    touch(Template(r"tpl1598285699187.png", record_pos=(-0.264, -0.101), resolution=(960.0, 540.0)),times=3,duration=0.1)
    touch(Template(r"tpl1598285704178.png", record_pos=(-0.169, -0.106), resolution=(960.0, 540.0)),times=3,duration=0.1)
    touch(Template(r"tpl1598286674024.png", record_pos=(-0.049, -0.098), resolution=(960.0, 540.0)),times=3,duration=0.1)
    touch(Template(r"tpl1598286680932.png", record_pos=(0.378, 0.189), resolution=(960.0, 540.0)))


    sleep(33)

    fight_end()


    touch(v=half_num,times=30,duration=0.1)
    
    sleep(5)

    touch(Template(r"tpl1598286808659.png", record_pos=(-0.286, 0.252), resolution=(960.0, 540.0)))

    sleep(5)

    touch(Template(r"tpl1598286815203.png", record_pos=(0.297, -0.136), resolution=(960.0, 540.0)))

    sleep(1)

    touch(v=half_num,times=50,duration=0.1)

    sleep(1)
    touch(Template(r"tpl1598360577348.png", record_pos=(-0.36, -0.135), resolution=(960, 540)))

    sleep(2)
    touch(Template(r"tpl1598286841098.png", record_pos=(0.333, 0.172), resolution=(960.0, 540.0)))
    sleep(5)
    touch(Template(r"tpl1598360600791.png", record_pos=(-0.398, -0.041), resolution=(960, 540)))

    sleep(2)
    touch(Template(r"tpl1598286864516.png", record_pos=(0.327, 0.176), resolution=(960.0, 540.0)))
    sleep(5)

    touch(v=half_num,times=20,duration=0.1)

    sleep(2)

    touch(Template(r"tpl1598286884198.png", record_pos=(0.282, 0.248), resolution=(960.0, 540.0)))


    touch(v=half_num,times=30,duration=0.1)

    sleep(3)

    touch(Template(r"tpl1598286915302.png", record_pos=(0.248, 0.098), resolution=(960.0, 540.0)))

    sleep(1)
    touch(v=half_num,times=25,duration=0.1)

    sleep(1)
    touch(Template(r"tpl1598286936103.png", record_pos=(0.434, -0.231), resolution=(960.0, 540.0)))

    sleep(2)

    touch(v=half_num,times=15,duration=0.1)

    sleep(5)
    touch(v=half_num,times=15,duration=0.1)

    touch(Template(r"tpl1598286964060.png", record_pos=(0.0, 0.249), resolution=(960.0, 540.0)))
    sleep(5)

    touch(Template(r"tpl1598286973501.png", record_pos=(0.078, -0.078), resolution=(960.0, 540.0)))
    sleep(2)

    touch(Template(r"tpl1598286982371.png", record_pos=(-0.258, -0.041), resolution=(960.0, 540.0)))

    touch(Template(r"tpl1598286996013.png", record_pos=(0.37, 0.2), resolution=(960.0, 540.0)))

    sleep(2)

    touch(v=h_w_num(0.533,0.299))
    sleep(1)

    touch(Template(r"tpl1598287053620.png", record_pos=(0.37, 0.192), resolution=(960.0, 540.0)))

    sleep(30)

    fight_end()
    
    sleep(2)

    touch(v=half_num,times=30,duration=0.1)

    sleep(3)
    touch(Template(r"tpl1598287183878.png", record_pos=(0.454, 0.167), resolution=(960.0, 540.0)))
    sleep(2)

    touch(v=half_num,times=30,duration=0.1)
    sleep(3)
    touch(Template(r"tpl1598287199853.png", record_pos=(0.377, 0.175), resolution=(960.0, 540.0)))
    sleep(2)
    touch(Template(r"tpl1598287210581.png", record_pos=(-0.004, 0.215), resolution=(960.0, 540.0)))

    sleep(2)
    touch(v=half_num,times=15,duration=0.1)
    sleep(2)

    result_ok_down = exists(Template(r"tpl1598287231941.png", record_pos=(0.108, 0.107), resolution=(960.0, 540.0)))
    if result_ok_down:
        touch(Template(r"tpl1598287231941.png", record_pos=(0.108, 0.107), resolution=(960.0, 540.0)))
        sleep(10)

    sleep(2)
def four_pcr():    
    sleep(8)
    touch(v=half_num,times=20,duration=0.1)
    sleep(8)

    for num in range(60):
        result_start = exists(Template(r"tpl1598525928005.png", record_pos=(0.005, -0.002), resolution=(960, 540)))
        if result_start:
            break
        sleep(1)
        touch(v=half_num,times=5,duration=0.1)
    touch(v=(0.937*width,0.08*height),times=5,duration=0.1)
    sleep(10)
    touch(v=(0.937*width,0.08*height),times=10,duration=0.1)
    sleep(3)
    touch(v=half_num,times=5,duration=0.1)
    result_activity = exists(Template(r"tpl1598362479732.png", record_pos=(0.442, -0.236), resolution=(960, 540)))
    if result_activity:
        touch(Template(r"tpl1598362479732.png", record_pos=(0.442, -0.236), resolution=(960, 540)))
        touch(v=half_num,times=10,duration=0.1)
#         touch(v=(0.476*width,0.211*height),times=20,duration=0.1)
        touch(Template(r"tpl1598362594633.png", record_pos=(0.113, 0.105), resolution=(960, 540)))
        touch(v=(0.424*width,0.224*height),times=5,duration=0.1)
    sleep(5)
    touch(v=(0.811*width,0.548*height),times=50,duration=0.1)
    true_touch(Template(r"tpl1598362660103.png", record_pos=(0.374, 0.232), resolution=(960, 540)))
    
    touch(wait(Template(r"tpl1598362675814.png", record_pos=(0.426, -0.245), resolution=(960, 540))))

    touch(v=(0.444*width,0.429*height),times=5,duration=0.1)
    touch(v=(0.811*width,0.548*height),times=5,duration=0.1)
    sleep(3)
    touch(v=(0.811*width,0.548*height),times=20,duration=0.1)
def start_location(file_name):
    sleep(3)
    touch(Template(r"tpl1598362694889.png", record_pos=(-0.002, 0.218), resolution=(960, 540)))
    sleep(3)
    touch(Template(r"tpl1598362719856.png", record_pos=(-0.104, 0.227), resolution=(960, 540)))
    sleep(3)
    touch(Template(r"tpl1598362734167.png", record_pos=(-0.113, 0.174), resolution=(960, 540)))
    touch(Template(r"tpl1598362752807.png", record_pos=(0.447, 0.17), resolution=(960, 540)))
    for num in range(2):
        touch(Template(r"tpl1598362765965.png", record_pos=(0.339, 0.216), resolution=(960, 540)))
        touch(Template(r"tpl1598362775398.png", record_pos=(0.11, 0.218), resolution=(960, 540)))
        sleep(3)
        touch(Template(r"tpl1598362785658.png", record_pos=(0.001, 0.221), resolution=(960, 540)))
        sleep(2)
    touch(Template(r"tpl1598362873886.png", record_pos=(0.109, 0.217), resolution=(960, 540)))
    sleep(2)
    
    save_password(file_name)
    all_task()
    
    sleep(2)
    touch(v=(0.77*width,0.903*height),times=10,duration=0.1)
    sleep(3)

    result_while_cat = exists(Template(r"tpl1598450070999.png", record_pos=(-0.003, -0.174), resolution=(960, 540)))
    if result_while_cat:
        sleep(3)
        touch(v=(0.63*width,0.688*height),times=5,duration=0.1)
        sleep(3)
        for num in range(60):
            resulr_ok_whilt = exists(Template(r"tpl1598604698384.png", record_pos=(0.116, 0.106), resolution=(960, 540)))
            if resulr_ok_whilt:
                sleep(2)
                touch(Template(r"tpl1598604698384.png", record_pos=(0.116, 0.106), resolution=(960, 540)))
                break
            sleep(1)
            touch(v=h_w_num(0.628,0.471),times=5,duration=0.1)  
        sleep(3)
        result_ok_while = exists(Template(r"tpl1598450143706.png", record_pos=(0.13, 0.105), resolution=(960, 540)))
        if result_ok_while:
            sleep(2)
            touch(Template(r"tpl1598450187537.png", record_pos=(-0.002, 0.216), resolution=(960, 540)))

    sleep(4)

    touch(Template(r"tpl1598849070767.png", record_pos=(0.401, 0.074), resolution=(960, 540)))

    touch(Template(r"tpl1598362923074.png", record_pos=(0.11, 0.222), resolution=(960, 540)))
def eq_goin(num_str):
    flag_out = 1
    while flag_out == 1 :
        touch(v=(0.955*width,0.043*height),times=20,duration=0.05)
        result_goin = exists(Template(r"tpl1598362998424.png", record_pos=(0.11, 0.177), resolution=(960, 540)))
        if result_goin:
            touch(v=(0.6*width,0.821*height),times=3,duration=0.05)
            result_ok_exists = exists(Template(r"tpl1598451988281.png", rgb=True, record_pos=(0.116, 0.22), resolution=(960, 540)))
            if result_ok_exists:
                touch(Template(r"tpl1598451988281.png", rgb=True, record_pos=(0.116, 0.22), resolution=(960, 540)))
                continue
            result_no_monery = exists(Template(r"tpl1598365339162.png", record_pos=(0.11, 0.218), resolution=(960, 540)))
            if result_no_monery:
                touch(Template(r"tpl1598365388531.png", record_pos=(-0.114, 0.217), resolution=(960, 540)))
                sleep(2)
                touch(Template(r"tpl1598365405169.png", record_pos=(-0.117, 0.183), resolution=(960, 540)))
                sleep(4)
                touch(Template(r"tpl1598365427285.png", record_pos=(-0.269, 0.253), resolution=(960, 540)),times=10,duration=0.05)
                break            

        else:
            result_end = exists(Template(r"tpl1598371000658.png", rgb=True, record_pos=(-0.002, 0.18), resolution=(960, 540)))
            if result_end:
                touch(Template(r"tpl1598371000658.png", rgb=True, record_pos=(-0.002, 0.18), resolution=(960, 540)),times=5,duration=0.05)
                sleep(3)
                if num_str == 1:
                    touch(v=(0.076*width,0.788*height),times=5,duration=0.05)
                sleep(4)
                touch(v=(0.89*width,0.642*height),times=3,duration=0.05)
                result_no_monery = exists(Template(r"tpl1598365339162.png", record_pos=(0.11, 0.218), resolution=(960, 540)))
                if result_no_monery:
                    touch(v=(0.379*width,0.875*height),times=8,duration=0.05)
                    sleep(1)
                    touch(v=(0.379*width,0.875*height),times=8,duration=0.05)
                    sleep(3)
                    touch(Template(r"tpl1598365427285.png", record_pos=(-0.269, 0.253), resolution=(960, 540)),times=10,duration=0.05)
                    break
                touch(Template(r"tpl1598362923074.png", rgb=True, record_pos=(0.11, 0.222), resolution=(960, 540)))
                
                sleep(3)
def save_image(file_name):    
    sleep(2)
    result_ox = exists(Template(r"tpl1598499010351.png", record_pos=(0.428, -0.251), resolution=(960, 540)))
    for num in range(60):
        if result_ox:
            touch(v=h_w_num(0.927,0.054),times=5,duration=0.05)
            result_zoom = exists(Template(r"tpl1598499038216.png", record_pos=(0.403, -0.069), resolution=(960, 540)))
            if result_zoom:
                break
            sleep(1)
    sleep(2)
    touch(Template(r"tpl1598499038216.png", record_pos=(0.403, -0.069), resolution=(960, 540)))
    touch(Template(r"tpl1598499060123.png", record_pos=(0.164, -0.185), resolution=(960, 540)))
    touch(Template(r"tpl1598499072447.png", record_pos=(0.293, -0.133), resolution=(960, 540)))
    touch(Template(r"tpl1598499079816.png", record_pos=(0.117, 0.22), resolution=(960, 540)))
    sleep(2)    
    snapshot(filename=("F://util//pcr//"+file_name +"hezi.jpg"))
    sleep(1)
    touch(Template(r"tpl1598500091568.png", record_pos=(0.197, 0.188), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500100763.png", record_pos=(0.002, 0.216), resolution=(960, 540)))
    sleep(1)
def save_password(file_name):
    touch(Template(r"tpl1598500123808.png", record_pos=(0.414, 0.246), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500140867.png", record_pos=(0.115, -0.026), resolution=(960, 540)),times=3)
    sleep(1)
    touch(Template(r"tpl1598500148183.png", record_pos=(0.117, 0.17), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500175353.png", record_pos=(-0.109, -0.006), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500184581.png", record_pos=(0.115, 0.168), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500204690.png", record_pos=(-0.158, -0.132), resolution=(960, 540)))
    sleep(1)
    text("Xiaoyun461")
    touch(Template(r"tpl1598500238255.png", record_pos=(0.429, 0.216), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500251803.png", record_pos=(-0.183, -0.037), resolution=(960, 540)))
    sleep(1)
    text("Xiaoyun461")
    touch(Template(r"tpl1598500238255.png", record_pos=(0.429, 0.216), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500288789.png", record_pos=(-0.164, 0.142), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500295904.png", rgb=True, record_pos=(0.114, 0.217), resolution=(960, 540)))
    sleep(1)
    touch(Template(r"tpl1598500362921.png", record_pos=(0.0, 0.109), resolution=(960, 540)))
    sleep(2)
    touch(Template(r"tpl1598500373208.png", record_pos=(-0.115, -0.091), resolution=(960, 540)))
    sleep(2)
    true_touch(Template(r"tpl1598500391169.png", record_pos=(-0.114, 0.173), resolution=(960, 540)))
    sleep(3)
    snapshot(filename=("F://util//pcr//"+file_name +".jpg"))
def all_task():
    sleep(2)
    touch(v=(0.097*width,0.925*height),times=20,duration=0.05)
    sleep(3)
    true_touch(Template(r"tpl1598526663155.png", record_pos=(-0.002, 0.216), resolution=(960, 540)))
    sleep(4)
    true_touch(Template(r"tpl1598526682541.png", record_pos=(-0.116, 0.214), resolution=(960, 540)))
    sleep(2)
    touch(Template(r"tpl1598515861906.png", record_pos=(0.373, 0.177), resolution=(960, 540)))

    sleep(4)
    
    touch(v=(0.577*width,0.047*height),times=10,duration=0.05)
    sleep(2)
    touch(Template(r"tpl1598516004299.png", record_pos=(0.376, 0.175), resolution=(960, 540)))
    touch(Template(r"tpl1598516014599.png", record_pos=(0.002, 0.217), resolution=(960, 540)))
    sleep(4)
    true_touch(Template(r"tpl1598516023263.png", record_pos=(-0.003, 0.104), resolution=(960, 540)))

def stop_func_print(attempts, delay):
    print("stop_func %d--->%d" % (attempts,delay))
# @retry(wait_fixed=2000,stop_func=stop_func_print)
def for_num_with():
    for num  in range(60):
        file_name = str(uuid.uuid1())[1:8]
        es()
        start_pcr(1)
        init_first()
        second_pcr()
        third_pcr()
        four_pcr()
        start_location(file_name)
        eq_goin(0)
        save_image(file_name)
height = 0
width = 0
connect_device("Android:///127.0.0.1:7555")
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
for_num_with()


# height_width()
# file_name = str(uuid.uuid1())[1:8]
# # # # # # all_task()
# # # # # # start_location(file_name)
# # # # four_pcr()
# start_location(file_name)
# eq_goin(0)
# save_image(file_name)


    